package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TablePIncomePay;
import com.ruoyi.system.service.ITablePIncomePayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首付款管理Controller
 * 
 * @author ruoyi
 * @date 2022-06-04
 */
@Controller
@RequestMapping("/system/pay")
public class TablePIncomePayController extends BaseController
{
    private String prefix = "system/pay";

    @Autowired
    private ITablePIncomePayService tablePIncomePayService;

    @RequiresPermissions("system:pay:view")
    @GetMapping()
    public String pay()
    {
        return prefix + "/pay";
    }

    /**
     * 查询首付款管理列表
     */
    @RequiresPermissions("system:pay:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TablePIncomePay tablePIncomePay)
    {
        startPage();
        List<TablePIncomePay> list = tablePIncomePayService.selectTablePIncomePayList(tablePIncomePay);
        return getDataTable(list);
    }

    /**
     * 导出首付款管理列表
     */
    @RequiresPermissions("system:pay:export")
    @Log(title = "首付款管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TablePIncomePay tablePIncomePay)
    {
        List<TablePIncomePay> list = tablePIncomePayService.selectTablePIncomePayList(tablePIncomePay);
        ExcelUtil<TablePIncomePay> util = new ExcelUtil<TablePIncomePay>(TablePIncomePay.class);
        return util.exportExcel(list, "首付款管理数据");
    }

    /**
     * 新增首付款管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首付款管理
     */
    @RequiresPermissions("system:pay:add")
    @Log(title = "首付款管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TablePIncomePay tablePIncomePay)
    {
        return toAjax(tablePIncomePayService.insertTablePIncomePay(tablePIncomePay));
    }

    /**
     * 修改首付款管理
     */
    @RequiresPermissions("system:pay:edit")
    @GetMapping("/edit/{incomePayId}")
    public String edit(@PathVariable("incomePayId") Long incomePayId, ModelMap mmap)
    {
        TablePIncomePay tablePIncomePay = tablePIncomePayService.selectTablePIncomePayByIncomePayId(incomePayId);
        mmap.put("tablePIncomePay", tablePIncomePay);
        return prefix + "/edit";
    }

    /**
     * 修改保存首付款管理
     */
    @RequiresPermissions("system:pay:edit")
    @Log(title = "首付款管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TablePIncomePay tablePIncomePay)
    {
        return toAjax(tablePIncomePayService.updateTablePIncomePay(tablePIncomePay));
    }

    /**
     * 删除首付款管理
     */
    @RequiresPermissions("system:pay:remove")
    @Log(title = "首付款管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tablePIncomePayService.deleteTablePIncomePayByIncomePayIds(ids));
    }
}
